//
//  GameListCell.swift
//  d11
//
//  Created by peale on 2018/10/16.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit

class GameListCell: UICollectionViewCell {
    var imageView: UIImageView!
    
    var titleLabel: UILabel!
    
    override init(frame:CGRect){
        super.init(frame: frame)
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        self.imageView = UIImageView()
        self.imageView.contentMode = UIView.ContentMode.scaleAspectFit
        self.imageView.image = imageNamed("img_default_60")
        self.contentView.addSubview(imageView)
        self.imageView?.snp.makeConstraints{(make) in
            make.width.equalToSuperview().offset(-10)
            make.height.equalToSuperview().offset(-35)
            make.centerX.equalTo(self.contentView)
        }
        self.titleLabel = UILabel()
        self.titleLabel.font = UIFont.systemFont(ofSize: 13)
        self.titleLabel.textAlignment = .center
        self.titleLabel.textColor = UIColor.black
        self.contentView.addSubview(self.titleLabel)
        self.titleLabel?.snp.makeConstraints{(make) in
            make.width.equalToSuperview().offset(-10)
            make.height.equalTo(25)
            make.top.equalTo(self.imageView.snp.bottom)
            make.centerX.equalTo(self.contentView)
        }
        self.backgroundColor = UIColor.white
        
    }
    
    func setData(dict : [String:Any]) -> Void {
        let imgurl = dict["imgurl"] as? String ?? ""
        self.imageView.sd_setImage(with:kMainUrl("\(imgurl)") , placeholderImage: imageNamed("img_default_60"), options: .refreshCached, completed: nil)
      
        self.titleLabel.text =  dict["title"] as? String
    }
}
